
import Api, { GET_USER_INFO, SET_ADDRESS,GET_DEFAULT_ADDR } from '../../utils/api.js';
import {getUrl} from '../../utils/util.js';

const App = getApp();

Page({
    data: {
        info: {},
        addr:{},
        common_menu: [
            { idx: 1, icon: "../../img/public/wallet.png", name: "待付款" },
            { idx: 3, icon: "../../img/public/wallet.png", name: "待收货" },
            { idx: 4, icon: "../../img/public/wallet.png", name: "待评价" },
            { idx: 5, icon: "../../img/public/wallet.png", name: "售后/退款" },
            { idx: 0, icon: "../../img/public/wallet.png", name: "全部订单" },
        ],
        all_menu:[
            [
                { icon: "../../img/public/wallet.png", name: "我的收藏", url: "collect/collect" },
                { icon: "../../img/public/wallet.png", name: "足迹", url: "footmark/footmark" },
            ],
            [
                { icon: "../../img/public/wallet.png", name: "意见反馈", url: "feedback/feedback" },
                // { icon: "../../img/public/wallet.png", name: "兑换记录",url:"record/record"},
                { icon: "../../img/public/wallet.png", name: "联系客服", url: "" },
                { icon: "../../img/public/wallet.png", name: "联系我们", url: "contact_us/contact_us" },
            ]
        ]
      
        
    },
    setAddress: function () {
        let _this = this,
            { key } = this.data;
        wx.chooseAddress({
            success: function (res) {
                let obj = {
                    key: key,
                    name: res.userName,
                    prov: res.provinceName,
                    city: res.cityName,
                    county: res.countyName,
                    detail: res.detailInfo,
                    mobile: res.telNumber
                }
                Api.fetch(SET_ADDRESS, obj, resp => {
                    _this.setData({
                        addr: obj
                    })
                })
            }
        })
    },
    // 通用页面跳转
    navigateTo: function (e) {
        let { idx, tip, url, name } = e.currentTarget.dataset;
       
        if (tip == 'menu') {
            url = getUrl('menu',{type:idx});
        }
        if (name!='联系客服'){
            App.navigateTo(url)
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let _this = this,
            key;


        //判断是否登录
        if (Api.checkLogin(function () {
            _this.onLoad();
        })) {
            key = Api.getKey();
            //获取用户数据接口
      
        }

        Api.fetch(GET_USER_INFO, { key: key }, resp => {
            this.setData({
                info: resp,
                key: key
            })
        })

        Api.fetch(GET_DEFAULT_ADDR,{key:key}, resp=>{
            if(resp){
                this.setData({
                    addr: resp
                })
            }
            
        })
    },
    contack:function(){
        
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})